package chain.node;

import chain.Handler;
import chain.PaymentRequest;

import java.util.Arrays;

public class RegionChecker extends Handler {
    @Override
    public void handlePaymentRequest(PaymentRequest request) throws Exception {
        // 目前只在 CN, US 两个地区开放支付
        String[] openCountry = new String[]{"CN", "US"};
        if (!Arrays.asList(openCountry).contains(request.getUserRegion())) {
            throw new Exception(request.getUserRegion() + " not open online payment, " + Arrays.toString(openCountry) + " had open.");
        }
        System.out.println("region check success");
        if (nextHandler != null) {
            nextHandler.handlePaymentRequest(request);
        }
    }
}
